<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <title>新建考核任务</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>


    <script type="text/javascript" charset="utf-8" src="/lib/jQuery-File-Upload-master/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/laydate/laydate.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/layer/layer.js?20201106"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" ></script>
    <script type="text/javascript" charset="utf-8" src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" ></script>
    <script type="text/javascript" charset="utf-8" src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" ></script>
    <script type="text/javascript" charset="utf-8" src="/js/base/base.js"></script>
    <style>
        a{
            text-decoration: none;
        }
        .main{
            width: 788px;
            margin: 0 auto;
            box-sizing: border-box;
            box-shadow: 0px 0px 16px 5px #b8b3b3;
            padding: 14px;
        }
        .nav{
            height: 40px;
            border-bottom: 1px solid #000;
            font-size: 22px;
            padding-top: 10px;
            font-weight: 400;
        }
        .leftspan{
            display: inline-block;
            width: 156px;
            text-align: right;
            margin-right: 52px;
        }
        ul,li{
            list-style: none;
            margin:12px 0;
            padding: 0;
        }
        input{
            width: 376px;
            height: 30px;
            border: 1px solid #ccc;
            border-radius: 2px;
            padding-left: 6px;
        }
        .inputsmall{
            width: 154px;
            height: 30px;
            text-align: center;
            padding-left: 0px;
        }
        .line{
            margin: 0 21px;
        }
        .btn{
            font-size: 14px;
            background-color: #008cffd9;
            padding: 4px 18px;
            border-radius: 3px;
            color: #fff;
            cursor:pointer;
        }
        textarea{
            width: 376px;
            height: 76px;
            padding-left: 6px;
        }
        .spspan{
            position: relative;
            bottom: 60px;
        }
        .list{
            text-align: center;
            margin: 60px 0;
        }
        .list span{
            font-size: 18px;
            background-color: #008cffd9;
            padding: 6px 48px;
            border-radius: 3px;
            color: #fff;
            cursor: pointer;
            margin: 0 3px;
        }
        .uploadbox{
            margin-left: 217px;
            padding-top: 6px;
        }
        select {
            width: 376px;
            height: 30px;
            border: 1px solid #ccc;
            border-radius: 2px;
            padding-left: 6px;
        }
        .mustinput{
            color: red;
            height: 26px;
            line-height: 32px;
            margin-left: 5px;
        }
    </style>
</head>
<body>
<div class="main">

    <ul>
        <li>
            <span class="leftspan">考核任务标题：<font class="mustinput">*</font></span>

            <span><input type="text" id="budgetItemNo"></span>
        </li>
        <li>
            <span class="leftspan">考核人：<font class="mustinput">*</font></span>

            <span><input disabled type="text" id="department"></span>
            <span class="btn adddept">添加</span>
            <span class="btn clear">清除</span>
        </li>
        <li>
            <span class="leftspan">被考核人：<font class="mustinput">*</font></span>

            <input disabled class="td_title1 release1" id="itemExecuter" type="text" username="">
            <a href="javascript:;" class=" ml8 userPrivAdd btn add4" name="orgAdd">添加</a>
            <a href="javascript:;" class=" ml8 userPrivClear btn clear4" name="orgClear">清除</a>
        </li>
        <li>
            <span class="leftspan">考核任务查看者：<font class="mustinput">*</font></span>


            <input disabled class="td_title1 release1" id="itemManager" type="text" username="">
            <a href="javascript:;" class=" ml8 userPrivAdd btn add3" name="orgAdd">添加</a>
            <a href="javascript:;" class=" ml8 userPrivClear btn clear3" name="orgClear">清除</a>
        </li>
        <li>
            <span class="leftspan">考核指标集：<font class="mustinput">*</font></span>
            <select name="postPriv" class="BigSelect" id="priveItem">
                <option value="">请选择</option>

            </select>
        </li>

        <li>
            <span class="leftspan">有效期：<font class="mustinput">*</font></span>
            <span><input type="text" placeholder="请选择日期" id="budgetItemBegintime" class="inputsmall" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  ></span>
            <span class="line">至</span>
            <span><input type="text" placeholder="请选择日期" id="budgetItemEndtime" class="inputsmall" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  ></span>
        </li>
        <li>
            <span class="leftspan spspan">描述：<font class="mustinput">&nbsp;</font></span>
            <span><textarea name=""  id="itemDesc"></textarea></span>
        </li>
        <li class="list"><span id="save">保存</span><span class="back">返回</span></li>
    </ul>
</div>
</body>
<script>
    //截取字符串
    function getRequest() {
        var url = window.location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {

                theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);

            }
        }
        return theRequest;
    }
    var flowId= getRequest().flowId;
    function inputcheck(name,value) {
        $('#'+name+'').val(value)
    }
    function slecetcheck(name,value) {
        $('#'+name+'').html(value)
    }
    //编辑值的回显
    function mustWrite() {
        if ($('#budgetItemNo').val() == "") {
            $.layerMsg({content: '考核任务标题！', icon: 2});
            return false;
        }
        if ($('#priveItem').val() == "") {
            $.layerMsg({content: '请选择考核指标集！', icon: 2});
            return false;
        }
        if ($('#department').val() == "") {
            $.layerMsg({content: '请选择考核人！', icon: 2});
            return false;
        }
        if ($('#itemManager').val() == "") {
            $.layerMsg({content: '请选择考核任务查看者！', icon: 2});
            return false;
        }
        if ($('#itemExecuter').val() == "") {
            $.layerMsg({content: '请选择被考核人！', icon: 2});
            return false;
        }
    }
    if(!(getRequest().type==1)){
        $.ajax({
            type: 'post',
            url: '/ScoreFlowLeader/selScoreFlow',
            dataType: 'json',
            data: {
                flowId:flowId
            },
            success: function (res) {

                var objs=  res.obj[0]
                inputcheck('budgetItemNo',objs.flowTitle)
                inputcheck('department',objs.rankmanName)
                inputcheck('itemExecuter',objs.participantName)
                inputcheck('itemManager',objs.viewUserName)
                inputcheck('priveItem',objs.groupId)
                inputcheck('budgetItemBegintime',objs.beginDateStr)
                inputcheck('budgetItemEndtime',objs.endDateStr)
                inputcheck('itemDesc',objs.flowDesc)
            }
        })
        $('#save').click(function(){
            if(mustWrite()==false) {
                return;
            }
            var attachmentId = []
            var attachmentName = []
            if($('.uploadbox .inHidden')){
                for(var i=0;i < $('.uploadbox .inHidden').length;i++){
//                        attachmentId+=$('.uploadbox .inHidden').eq(i).val()+','
                    attachmentId+=$('.uploadbox ').find('.dech>a').eq(i*aTagNumber).attr('href')
                    attachmentName+=$('.uploadbox ').find('.dech>a').eq(i*aTagNumber).attr('NAME')+'*'
                }
            }
            if(attachmentId != ''){
                var attachmentIdArr = attachmentId.split('?')[1];
                var attachmentUrl= attachmentIdArr;
            }
            var budgetItemNo=$('#budgetItemNo').val();
            var department = $('#department').val().slice(0,$('#department').val().length-1);
            var itemExecuter = $('#itemExecuter').val().slice(0,$('#itemExecuter').val().length-1);
            var itemManager = $('#itemManager').val().slice(0,$('#itemManager').val().length-1);
            var priveItem = $('#priveItem option:selected').val();
            var budgetItemBegintime = $('#budgetItemBegintime').val();
            var budgetItemEndtime = $('#budgetItemEndtime').val();
            var itemDesc = $('#itemDesc').val();
            $.ajax({
                url:'/ScoreFlowLeader/modifyScoreFlow',
                type:'post',
                data:{
                    flowId:flowId,
                    flowTitle:budgetItemNo,
                    rankman:department,
                    participant:itemExecuter,
                    viewUserId:itemManager,
                    groupId:priveItem,
                    beginDateStr:budgetItemBegintime,
                    endDateStr:budgetItemEndtime,
                    flowDesc:itemDesc
                },
                dataType:'json',
                success:function(res){
                    if(res.msg=="新建项目重复"){
                        layer.msg("新建项目重复", {
                            icon: 2,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        });
                    }else {
                        layer.msg("修改成功", {
                            icon: 1,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            location.href = "/ScoreFlowLeader/assessmentTask"
                        });
                    }
                }
            })
        })

    }else{

    }


    //下拉框表集

    $.ajax({
        type:'get',
        url:'/ScoreGroupLeader/selScoreGroup',
        dataType:'json',
        success:function(res){
            var str='';
            if(res){
                $.each(res.obj,function(index,item){
                    str+='<option value="'+item.groupId+'">'+item.groupName+'</option>'
                });
                $('#priveItem').append(str);
            }
        }
    });


    $(function () {
        $('.adddept').click(function(){
            user_id='department';
            /*$.popWindow("../../common/roleMapper");*/
            $.popWindow("../../common/selectUser");
        })


        $('.add2').click(function(){
            layer.open({
                type:1,
                title: ['请选择部门', 'background-color:#2b7fe0;color:#fff;'],
                area: ['600px', '420px'],
                btn: ['导入', '取消'],
                content:'',
                success:function(){

                },
                yes:function(obj){
                }
            })
        })



        $('.add3').click(function(){
            user_id='itemManager';
            $.popWindow("../../common/selectUser");
        })
        $('.add4').click(function(){
            user_id='itemExecuter';
            $.popWindow("../../common/selectUser");
        })
        $('.clear').click(function(){
            $(this).siblings().find('input').removeAttr('deptname').removeAttr('deptno').removeAttr('deptid').removeAttr('user_id').val('')
        })
        // 清空人员信息
        $('.clear3').click(function () {
            $('#itemManager').attr("privid", "");
            $('#itemManager').attr("userpriv", "");
            $('#itemManager').attr("user_id", "");
            $('#itemManager').val("");
        });
        $('.clear4').click(function () {
            $('#itemExecuter').attr("privid", "");
            $('#itemExecuter').attr("userpriv", "");
            $('#itemExecuter').attr("user_id", "");
            $('#itemExecuter').val("");
        });
        $('.back').click(function(){
            location.href="/ScoreFlowLeader/assessmentTask"
        })
    })
</script>
</html>
